package com.jy.adscm.hospital.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.dealer.bean.Dealer;
import com.jy.adscm.dealer.mapper.DealerMapper;
import com.jy.adscm.hospital.bean.JyHospitalFunctionalDept;
import com.jy.adscm.hospital.bean.JyHospitalRemarks;
import com.jy.adscm.hospital.mapper.JyHospitalFunctionalDeptMapper;
import com.jy.adscm.hospital.service.JyHospitalFunctionalDeptService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 其他职能部门信息 服务实现类
 * </p>
 *
 * @author yyy
 * @since 2019-01-16
 */
@Service
public class JyHospitalFunctionalDeptServiceImpl extends ServiceImpl<JyHospitalFunctionalDeptMapper, JyHospitalFunctionalDept> implements JyHospitalFunctionalDeptService {
    private Logger logger = Logger.getLogger(getClass());

    @Autowired
    JyUserMapper jyUserMapper;

    @Autowired
    DealerMapper dealerMapper;

    @Override
    public List<JyHospitalFunctionalDept> selectList(Wrapper<JyHospitalFunctionalDept> wrapper) {

        logger.info("查询医院其他职能部门信息...");

        List<JyHospitalFunctionalDept> jyHospitalFunctionalDepts = super.selectList(wrapper);

        if (jyHospitalFunctionalDepts != null && jyHospitalFunctionalDepts.size()>0){
            for (JyHospitalFunctionalDept jyHospitalFunctionalDept : jyHospitalFunctionalDepts) {
                Integer inputUserId = jyHospitalFunctionalDept.getInputUserId();
                if (inputUserId != null){
                    JyUser user = jyUserMapper.selectById(inputUserId);
                    if (user != null){
                        jyHospitalFunctionalDept.setInputUserName(user.getName());
                    }
                }

                Integer inputUnit = jyHospitalFunctionalDept.getInputUnit();
                if (inputUnit == 0){
                    jyHospitalFunctionalDept.setInputUnitDesc("生产厂商");
                }else {
                    Dealer dealer = dealerMapper.selectById(inputUnit);
                    if (dealer != null){
                        jyHospitalFunctionalDept.setInputUnitDesc(dealer.getName());
                    }
                }
            }
        }

        return jyHospitalFunctionalDepts;
    }
}
